package com.lz.football.module.leagueMatch.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.events.LeagueMatchEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.club.vo.NpcClubInfoVo;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import lz.controls.ImageContain;

	/**
	 *传奇 
	 * @author lake
	 * 
	 */	
	public class LegendMatchPanel extends Sprite implements ILeagueMatchPanel
	{
		/**
		 * 皮肤
		 */		
		public var _symbolSkin			:MovieClip;
		/**
		 *开始按钮 
		 */		
		private var startBtn			:SimpleButton;
		
		public function LegendMatchPanel()
		{
			super();
		}
		
		/**
		 *初始化 
		 * 
		 */	
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.football.leaguematch.view.LegendMatchPanel");
			this.addChild(_symbolSkin);
			startBtn = _symbolSkin.startBtn;
			addEvtListener();
			_symbolSkin.txtName.text = "" + AppData.getInstance().clubDatamanager.clubInfo.uname;
			//自己队徽
			var iconId :int = AppData.getInstance().clubDatamanager.clubInfo.logo;
			var iconDisp :DisplayObject = Reflection.createInstance("com.football.team.icon_"+iconId);
			if(iconDisp == null)return;
			var showSize :Number = 125;
			var scxy :Number = ((showSize / iconDisp.width) <= (showSize / iconDisp.height))?(showSize / iconDisp.width):(showSize / iconDisp.height);
			iconDisp.scaleX = scxy;
			iconDisp.scaleY = scxy;
			DisplayObjectUtil.removeAllChildren(_symbolSkin.container);
			_symbolSkin.container.addChild(iconDisp);
			iconDisp.x = (showSize - iconDisp.width)/2;
			iconDisp.y = (showSize - iconDisp.height)/2;
		}
		/**
		 *注册事件 
		 * 
		 */	
		public function addEvtListener():void
		{
			startBtn.addEventListener(MouseEvent.CLICK,challengeHandler);
		}
		/**
		 *挑战 
		 * @param e
		 */		
		private function challengeHandler(e :MouseEvent):void
		{
			var param :Object = {};
			param.cid = 10019;
			this.dispatchEvent(new LeagueMatchEvent(LeagueMatchEvent.LEGEND_MATCH_START,param,true));
			//disable
			startBtn.mouseEnabled = false;
			startBtn.filters = [DisplayObjectUtil.DISABLE_FILTER];
		}
		/**
		 *删除事件 
		 * 
		 */	
		public function removeEvtListener():void
		{
			startBtn.removeEventListener(MouseEvent.CLICK,challengeHandler);
		}
		/**
		 *销毁 
		 * 
		 */	
		public function destroyView():void
		{
			removeEvtListener();
			_symbolSkin = null;
			startBtn = null;
			DisplayObjectUtil.removeAllChildren(this);
		}
		/********************** implements interface *********************************/
		/**
		 * 比赛开始
		 */		
		public function matchStart(value :Object = null):void
		{
			
		}
		/**
		 * 比赛结束
		 */		
		public function matchEnd(value :Object = null):void
		{
			
		}
		/**
		 * 错误返回
		 */		
		public function errorRes(value :Object = null):void
		{
			startBtn.mouseEnabled = true;
			startBtn.filters = null;
		}
	}
}